import sys
# 将子模块的路径添加到 Python 的模块搜索路径中
sys.path.append('../dxt')

from lin_base import *
from ut_misc import js_r

def shift_ra(ira):
    if ira < -6:
        ra = ira + 24 + 24
    else:
        ra = ira + 24
    return ra

        
def get_raxs_1_data():
    from raxs_1 import seg
    data=[]
    for ra,dec in seg:
        y = dec_to_y(dec)
        x = RA_to_x(g_share.x0, ra)
        data.append((x,y))
        
    return data

def get_raxs_1_n_segs():
    from raxs_1_n import segs
    return segs
def get_raxs_2_n_segs():
    from raxs_2_n import segs
    return segs
def get_raxs_3_n_segs():
    from raxs_3_n import segs
    return segs
def get_raxs_4_n_segs():
    from raxs_4_n import segs
    return segs
def get_raxs_5_n_segs():
    from raxs_5_n import segs
    return segs

get_raxs_n_n=[
    get_raxs_1_n_segs,
    get_raxs_2_n_segs,
    get_raxs_3_n_segs,
    get_raxs_4_n_segs,
    get_raxs_5_n_segs,
]

def convert_raxs_n_n_data(segs):
    datas=[]
    for seg in segs:
        data=[]
        for ra,dec in seg:
     
            y = dec_to_y(dec)
            x = RA_to_x(g_share.x0, ra)
            data.append((x,y))
        datas.append(data)
        
    return datas,segs

        
def get_raxs_n_data():
    n=1
    dicts={}
    for get_raxs in get_raxs_n_n:
        segs = get_raxs()
        print('get_raxs_n_data n:%d len:%d' % (n,len(segs)))
        dicts[n]= convert_raxs_n_n_data(segs)
        n+=1
    return dicts

def draw_milkyway_lin(paper):
    layer= paper.add_layer(name='mw')
    draw=layer.draw
    data = js_r(config.mw_path)
    color_sky = config.color_sky_day
    
    # milky way color
    mwc={
    1: (200,200,200,130), 
    2: (210,210,210,130),
    3: (220,220,220,130),
    4: (230,230,230,130),
    5: (240,240,240,130),
    }

    #dtss1= dtss[1]
    #print('dtss1[1]:%s' % dtss1[1])
    #draw.polygon(dtss1[0], outline=RED) #fill=mwc[1])
    #draw.polygon(dtss1[1], outline=BLUE) #fill=YELLOW) #(255,255,255,255))
    raxs_1_data = get_raxs_1_data()
    draw.polygon(raxs_1_data, fill=mwc[1])
    #raxs_0_data = get_raxs_0_data()
    #draw.polygon(raxs_0_data, outline=BLUE, width=2)
    
    dicts =get_raxs_n_data()
    raxs_1_n_data, segs = dicts[1]
    
    #raxs_1_n_data = get_raxs_1_n_data()
    for dts in raxs_1_n_data:
        draw.polygon(dts, fill=color_sky) #(255,255,255,255))

    for i in [2,3,4,5]:
        raxs_data,segs = dicts[i]
        for dts in raxs_data:
            if len(dts) < 3:
                continue
            draw.polygon(dts, fill=mwc[i]) #(255,255,255,255))
             

    
 